from Tools.console import print as p


class Question:
    title: str
    right: str
    options = []

    def __init__(self, title, right, options):
        self.title = title
        self.right = right
        self.options = options

    def print_ques(self):
        options = "\n".join(
            list(map(lambda option: "{}: {}".format(option[0], option[1]), self.options)))
        p(self.title, style="blue", end="\n\n", highlight=False)
        p(options, end="\n\n")

    def print_ques_with_answer(self):
        p(self.title, style="blue", end="\n\n", highlight=False)

        for option in self.options:
            if self.is_answer(option[0]):
                p("{}: {}".format(option[0], option[1]),
                  style="green", highlight=False)
            else:
                print("{}: {}".format(option[0], option[1]))

    def is_answer(self, option):
        return self.right == option

    def compare_answer(self, answer: str):
        return self.is_answer(answer.strip())

    def to_dict(self):
        return dict({
            'title': self.title,
            'right': self.right,
            'options': self.options,
        })
